<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      width: 100px;
      height: 100px;
    }

    .red {
      background-color: red;
    }
  </style>
</head>

<body>
  <div></div>

  <script>
    const elem = document.querySelector('div')

    // elem.className
    // elem.className = 'red'

    // elem.classList
    elem.classList.add('red')
  </script>
</body>

</html>